home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / fapxtool / src / txl / txllog.c < prev    next >
C/C++ Source or Header  |  1995-02-12  |  9KB  |  395 lines

  1. /***************
  2. *
  3. * g:\exe\txl\src\txllog.c
  4. */
  5. #include "txl.h"
  6.  
  7. #define BYTE(x) *((unsigned char *)(x))
  8. #define bit_chk(x,f) ((int)(BYTE(x+(f/8)) >> 7-f%8) & 1)
  9.  
  10. void logfindstr(FILE *input)
  11. {
  12.     long cline = 1;
  13.     int k, style, falseflg = 0x0000;/* cnt = 0;*/
  14.     char *mes_buf, *serchmax;
  15. #if 0
  16.     char **pftbl = &pfstr[0];
  17. #endif
  18.  
  19.     mes_buf = malloc(30000);
  20.     serchmax = mes_buf+28000;
  21.     if (mes_buf == NULL){
  22.         errexit("out of memory(-log)");
  23.     }
  24.     fread(mes_buf, 1, 1999, input);
  25.     log_bufptr = mes_buf;
  26.     while ((*log_bufptr != 0x0ff) && (cline < log_tline)) {
  27.         fread((mes_buf + 1999), 1, 28000, input);
  28.         while ((cline < log_tline) && (cline == 1)) {
  29.  
  30.             for (k = 0; k < MAX_STR; k++) {
  31.                 if ((*pfstr[k] == *log_bufptr) || (*pfstr[k] == '*')) {
  32.                     pfstr[k]++;
  33.                 }
  34.                 else {
  35.                     pfstr[k] = sfstr[k];
  36.                 }
  37.             }
  38.             if (*pfstr[0]==NUL) get_forum(1);
  39.             if (*pfstr[1]==NUL) get_forum(2);
  40.             if (*pfstr[2]==NUL) get_forum(2);
  41.             if (*pfstr[3]==NUL) get_libno(1);
  42.             if (*pfstr[4]==NUL) get_libno(2);
  43.             if (*pfstr[5]==NUL) {
  44.                 strncpy(log_idstr,log_bufptr+1,8); /* HPログ */
  45.             }
  46.             if (*pfstr[6]==NUL) strncpy(log_idstr,log_bufptr+1,8); /* catlog */
  47.             if ((*pfstr[7] == NUL) || (*pfstr[8] == NUL)) { /* パティオ */
  48.                 strncpy(log_pname,log_bufptr+1, 8);
  49.                 log_fname[0] = NUL;
  50.             }
  51.             if (*log_bufptr == 0x0a) cline++;
  52.             log_bufptr++;
  53.         }
  54.  
  55.         while ((cline < log_tline) && (log_bufptr < serchmax)) {
  56.             for (k = 0; k < MAX_STR; k++) {
  57.                 if ((*pfstr[k] == *log_bufptr) || (*pfstr[k] == '*')) {
  58.                     pfstr[k]++;
  59.                 }
  60.                 else {
  61.                     pfstr[k] = sfstr[k];
  62.                     falseflg |= (1 << k);
  63.                 }
  64.             }
  65.  
  66.             if (*pfstr[0]==NUL) get_forum(1);
  67.             else if (*pfstr[1]==NUL) get_forum(2);
  68.             else if (*pfstr[2]==NUL) get_forum(2);
  69.             else if (*pfstr[3]==NUL) get_libno(1);
  70.             else if (*pfstr[4]==NUL) get_libno(2);
  71.             else if (*pfstr[5]==NUL) {
  72.                 strncpy(log_idstr,log_bufptr+1,8); /* HPログ */
  73.                 cline++;
  74.             }
  75.             else if (*pfstr[6]==NUL) strncpy(log_idstr,log_bufptr+1,8);
  76.                 /* ↑catlog */
  77.             else if ((*pfstr[7] == NUL) || (*pfstr[8] == NUL)) {/* パティオ */
  78.                 strncpy(log_pname,log_bufptr+1, 8);
  79.                 log_fname[0] = NUL;
  80.                 if (*pfstr[7] == NUL) {
  81.                     cline++;
  82.                 }
  83.             }
  84.             if (falseflg == 0x1ff) {
  85.                 while (*log_bufptr != 0x0a) {
  86.                     log_bufptr++;
  87.                 }
  88.                 falseflg = 0x0000;
  89.                 cline++;
  90.             }
  91.             log_bufptr++;
  92. /*            if (*log_bufptr == 0x0a) cline++; */
  93.         }
  94.         /* ↓パフォーマンスは落ちるかもしれない */
  95.         while (kbhit()) {
  96.             if (getch() == 27) {
  97.                 fprintf(fpmes, "TXF:abort request.\n");
  98.                 free(mes_buf);
  99.                 Exit(1);
  100.             }
  101.         }
  102.  
  103.         if (cline < log_tline) {
  104. /*            strncpy(mes_buf, log_bufptr, 1999); */
  105.             strncpy(mes_buf, mes_buf + 28000, 1999);
  106.             log_bufptr -= 28000;
  107.         }
  108.     }
  109.  
  110.     if (cline == log_tline) {
  111.         style = linestyle();
  112.  
  113.         switch (style) {
  114.  
  115.         case 1: /* 会議室一覧 */
  116.         case 2: /* 会議室の境目 */
  117.         case 3: /* ストック会議室発言の題名 */
  118.         case 8: /* サイクリック会議室発言の題名/パティオの発言題名 */
  119.             meschk(style);
  120.             break;
  121.         case 4: /* データライブラリ一覧 */
  122.         case 5: /* 週間FTOWNS */
  123.         case 19:/* 引用1(引用文字半角) */
  124.         case 20:/* 引用2(引用文字全角) */
  125.             dlibchk(style);
  126.             break;
  127.         case 18:
  128.             fgalchk();
  129.             break;
  130.         case 6: /* hpの題名 */
  131.             hpchk();
  132.             break;
  133.         case 7: /* mailの題名 */
  134.         case 13: /* newmailの題名 */
  135.         case 10: /* from PC-VAN */
  136.         case 15: /* from PC-VAN newmail */
  137.             mailchk(style);
  138.             break;
  139. #if 0
  140.         case 9: /* FFMのデータライブラリ インフォメーション */
  141.             ffmtopchk();
  142.             break;
  143. #endif
  144.         case 12:
  145.             fravtopchk();
  146.             break;
  147.         case 11:
  148.         case 16:
  149.             widegatechk();
  150.             break;
  151.         case 14:
  152.             ffsutopchk(style);
  153.             break;
  154.         case 17:
  155.             maillistchk();
  156.             break;
  157.         default:
  158.             fprintf(fpmes, "Error:unknown line style");
  159.             fclose(input);
  160.             free(mes_buf);
  161.             Exit(1);
  162.         }
  163.     }
  164.     else {
  165.         fprintf(fpmes, "Error:find EOF before target line");
  166.         fclose(input);
  167.     }
  168.  
  169.     free(mes_buf);
  170. }
  171.  
  172. void logs()
  173. {
  174.     FILE *input = NULL;
  175.  
  176.     if (inputfile != NULL) input = fopen(inputfile, "rb");
  177.     if (input == NULL) {
  178.         fprintf(fpmes, "Error:cannot open input file '%s'\n", inputfile);
  179.         Exit(0);
  180.     }
  181.  
  182.     logfindstr(input);
  183.     fclose(input);
  184. }
  185.  
  186.  
  187. void loginit()
  188. {
  189.     int i;
  190.  
  191.     fprintf(stderr, "TXL: open LOGCHECK\n");
  192.  
  193.     for (i = 0; i < MAX_STR; i++) {
  194.         pfstr[i] = sfstr[i];
  195.     }
  196.     *log_handle = NUL;
  197.     log_hpstyle = -1;
  198.     log_hpchr = 0;
  199. }
  200.  
  201. void logdriver(char *val[])
  202. {
  203.     int i=0;
  204.  
  205.     loginit();
  206.  
  207.     for (i = 0; val[i] != NULL; i++) {
  208.  
  209.     if (val[i][0] == '-') {
  210.         switch (val[i][1]) {
  211.         case 'i':
  212.         case 'I':
  213.             if (val[i+1][0] != '-') inputfile = val[i+1];
  214.                 else i--;
  215.             break;
  216.         case 'l':
  217.         case 'L':
  218.             if (val[i+1][0] != '-') log_tline = atol(val[i+1]);
  219.                 else i--;
  220.         case 's':
  221.         case 'S':
  222.             if (val[i+1] != NULL) strncpy(log_resstr, val[i+1], 15);
  223.             break;
  224.         case 'H':
  225.             log_hpstyle++;
  226.         case 'h':
  227.             log_hpstyle++;
  228.             if (val[i][2] != NUL) {
  229.                 log_hpchr = (unsigned char)val[i][2];
  230.                 if (val[i][3] != NUL) {
  231.                     log_hpchr = (log_hpchr << 8) | (unsigned char)val[i][3];
  232.                 }
  233.             }
  234.             if (val[i+1] != NULL) strncpy(log_handle, val[i+1], 16);
  235.             break;
  236.         default:
  237.             fprintf(fpmes, "Error:invailed parameter'%s'\n", val[i]);
  238.             Exit(1);
  239.         }
  240.         i++;
  241.     }
  242.     else if (inputfile == NULL) {
  243.         inputfile = val[i];
  244.     }
  245.     else if ((inputfile != NULL) && (log_tline == 0)) {
  246.         log_tline = atol(val[i]);
  247.     }
  248.     else if ((inputfile != NULL) && (log_tline != 0) && (*log_resstr == NUL)) {
  249.         strncpy(log_resstr,val[i], 15);
  250.     }
  251.     else if ((inputfile != NULL) && (log_tline != 0) && (*log_resstr != NUL)) {
  252.         strncpy(log_handle, val[i], 16);
  253.     }
  254.  
  255.     }
  256.     logs();
  257.     Exit(0);
  258. }
  259.  
  260. int matchstr(char *form, char far *txtptr)
  261. {
  262.     char far *logtmp;
  263.     char *strtmp;
  264.     int i, trueflg = 0, count = 0;
  265.  
  266.     logtmp = txtptr;
  267.     strtmp = form;
  268. /*    while ((*strtmp != NUL) && (*logtmp != 0x0a)) {    */
  269.     while (*strtmp != NUL) {
  270.         trueflg = FALSE;
  271.         switch (*strtmp) {
  272.         case '%':
  273.             if (isdigit(*logtmp) || (*logtmp == ' ')) {
  274.                 trueflg = TRUE;
  275.             }
  276.             break;
  277.         case '*':
  278.             if (isalpha(*logtmp)) {
  279.                 trueflg = TRUE;
  280.             }
  281.             break;
  282.         case '&':
  283.             if (isalpha(*logtmp) || isdigit(*logtmp)) {
  284.                 trueflg = TRUE;
  285.             }
  286.             break;
  287.         case '_':
  288.             if (*logtmp == ' ') {
  289.                 trueflg = TRUE;
  290.             }
  291.             break;
  292.         case '$':
  293.             trueflg = TRUE;
  294.             break;
  295.         case 0x27:
  296.             strtmp++;
  297.             if (*logtmp == *strtmp) {
  298.                 trueflg = TRUE;
  299.             }
  300.             break;
  301.         case '^':
  302.             strtmp++;
  303.             count = ((*strtmp) - ('0'));
  304.             strtmp++;
  305.             while (trueflg != TRUE) {
  306.                 for (i = 0; i < count; i++) {
  307.                     if ((*(logtmp + i) != *(strtmp + i)) || (*(logtmp + i) == 0x0d)) {
  308.                         break;
  309.                     }
  310.                 }
  311.                 if (i != count) {
  312.                     logtmp++;
  313.                     if (*logtmp == 0x0a) {
  314.                         break;
  315.                     }
  316.                 }
  317.                 else {
  318.                     trueflg = TRUE;
  319.                 }
  320.             }
  321.             break;
  322.         default:
  323.             if (islower(*strtmp)) {
  324.                 if (tolower(*logtmp) == *strtmp) {
  325.                     trueflg = TRUE;
  326.                 }
  327.             }
  328.             else {
  329.                 if (*logtmp == *strtmp) {
  330.                     trueflg = TRUE;
  331.                 }
  332.             }
  333.         }
  334. /*        fprintf(stdout, "matchstr:%c,%c:", *strtmp, *logtmp);    */
  335.         if (trueflg != TRUE) {
  336. /*            puts("NG!");                                */
  337.             return (FALSE);
  338.         }
  339. /*        puts("GOOD!");                                    */
  340.         strtmp++;
  341.         logtmp++;
  342.     }
  343.     return (TRUE);
  344.  
  345. }
  346.  
  347. int linestyle()
  348. {
  349. /*
  350. char logstr_mes1[30]="%%   %%%%% ( %%%)   %%/%%   ";
  351. char logstr_mes2[15]="- ^1  MES(%%):";
  352. char logstr_mes3[41]="%%%/%%%   ***%%%%%  $$$$$$$$$$$$$$$$  ";
  353. char logstr_mes4[42]="%%%%%/%%%%% ***%%%%%  $$$$$$$$$$$$$$$$ ";
  354. char logstr_dlib[42]="%%%%$ ***%%%%% %%/%%/%% %%%%%%% %%%% * ";
  355. char logstr_hp[40]="%%%  [%%/%%/%% %%:%%]  ***%%%%%      ";
  356. char logstr_mail[44]="%% $$$$$$$$$$$$$$$$$  ***%%%%%  %%/%% %%:%%";
  357. char logstr_ffmtop[22]="%%/%%[^1]^3(DL%%-%%%)";
  358. char logstr_pcvm[44]="%%  -              PCV>***%%%%% %%/%% %%:%%";
  359. char logstr_wide[44]="%%  WIDE GATE         ***%%%%%  %%/%% %%:%%";
  360. char logstr_wftowns[5]="  #%";
  361. */
  362. /*
  363.     *(log_bufptr + 80) = NUL;
  364.     puts(log_bufptr);
  365. */
  366.  
  367.     if (matchstr(logstr_mes1,    log_bufptr)) return (1);
  368.     if (matchstr(logstr_mes2,    log_bufptr)) return (2);
  369.     if (matchstr(logstr_mes3,    log_bufptr)) return (3);
  370.     if (matchstr(logstr_dlib,    log_bufptr)) return (4);
  371.     if (matchstr(logstr_hp,      log_bufptr)) return (6);
  372.     if (matchstr(logstr_mes4,    log_bufptr)) return (8);
  373.  
  374.     if (matchstr(logstr_pcvm2,   log_bufptr)) return (15);
  375.     if (matchstr(logstr_wide2,   log_bufptr)) return (16);
  376.  
  377.     if (matchstr(logstr_mail2,   log_bufptr)) return (13);
  378.     if (matchstr(logstr_wftowns, log_bufptr)) return (5);
  379. #if 0
  380.     if (matchstr(logstr_ffmtop,  log_bufptr)) return (9);
  381. #endif
  382.     if (matchstr(logstr_fravtop, log_bufptr)) return (12);
  383.     if (matchstr(logstr_ffsutop, log_bufptr)) return (14);
  384.     if (matchstr(logstr_mlist,   log_bufptr)) return (17);
  385.     if (matchstr(logstr_qlib,    log_bufptr+1)) return (19);
  386.     if (matchstr(logstr_qlib,    log_bufptr+2)) return (20);
  387.     if (matchstr(logstr_fgallib, log_bufptr)) return (18);
  388.     if (matchstr(logstr_pcvm,    log_bufptr)) return (10);
  389.     if (matchstr(logstr_wide,    log_bufptr)) return (11);
  390.     if (matchstr(logstr_mail,    log_bufptr)) return (7);
  391.     return (0);
  392.  
  393. }
  394.  
  395.